<?
if (isset($_POST['btngo'])) {
    require("required/dbconnect.php");
    $pageno = $_POST['pageno'];
    header("Location:order_view.php?page=$pageno");
}


$title = "View all products";
$pageid = "1";
$accessid = "a00";

require("required/dbconnect.php");
require("required/function.php");
require("required/header.php");

checkAccess("allow_online_sales_view", 1);
?>
<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?
if (!empty($_GET['action'])) {
    switch ($_GET['action']) {
        case 1:
            $msg = "<div class='dw_success'>Data inserted</div>";
            break;
        case 2:
            $msg = "<div class='dw_success'>Data Deleted</div>";
            break;
        case 3:
            $msg = "<div class='dw_success'>Data Updated</div>";
            break;
        default:
            $msg = "";
            break;
    }
    echo "<script>displayMsg('divMsg')</script>";
} else {
    $msg = "";
}




if (isset($_POST['btnsubmit'])) {
    $status = $_POST['status'];

    if ($status == 0) {
        $option = "<option value=0>All</option>";
        $status_q = "";
    } else {
        $option = "<option value='$status'>" . billstatus_eng($status) . "</option>";
        $status_q = "and status=$status";
    }
} elseif (!empty($_GET['status'])) {
    $status = $_GET['status'];

    if ($status == 0) {
        $option = "<option value=0>All</option>";
        $status_q = "";
    } else {
        $option = "<option value='$status'>" . billstatus_eng($status) . "</option>";
        $status_q = "and status=$status";
    }
} else {
    $option = "<option value=0>All</option>";
    $status_q = "";
}


if (empty($_GET['page'])) {
    $page = "1";
} else {
    $page = $_GET['page'];
}

$totalperpage = 30;

$from = ($page - 1) * $totalperpage;

$get_bill = mysql_query("select * from os_bill_details where is_redeem=0 $status_q order by create_date desc limit $from,$totalperpage") or die(mysql_error());
$get_total = mysql_query("select * from os_bill_details where is_redeem=0 $status_q") or die(mysql_error());
?>
<table width="100%">

    <?
    $count = mysql_num_rows($get_total);

    $totalpage = $count / $totalperpage;

    if ($count % $totalperpage > 0) {
        if (round($totalpage) > $totalpage) {
            $totalpage = round($totalpage);
        } else {
            $totalpage = round($totalpage + 1);
        }
    } else {
        $totalpage = round($totalpage);
    }


    $nextpage = $page + 1;
    $prepage = $page - 1;
    ?>
    <td align="left" valign="top">
        <div class="title">View All Order</div>
        <div id="divMsg"><?= $msg ?></div>
        <table width="100%" cellpadding="2" cellspacing="1" >
            <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
                <td width="49%" colspan="5">
                    view status 
                    <select name="status" class="text">
                        <?= $option ?>
                        <option value="0">All</option>
                        <option value="-1">Expired order</option>
                        <option value="-2">Cancelled order</option>
                        <option value="1">Order under verifying</option>
                        <option value="7">Insufficient stock</option>
                        <option value="2">Order verified</option>
                        <option value="3">Buyer already make payment</option>
                        <option value="-3">Buyer choose to pay by Paypal</option>
                        <option value="-4">Paid by Paypal</option>
                        <option value="4">Machant already received payment</option>
                        <option value="5">Merchant shipped the goods</option>
                        <option value="6">Buyer already received the goods</option>
                    </select>
                    <input type="submit" value="Go" class="button" name="btnsubmit">
                </td>	
            </form>	
            <? if (mysql_num_rows($get_bill) == 0) { ?>
                <tr>
                    <td height="200" valign="middle" colspan="8" align="center">
                        <font color="#FF0000">- No order found -</font><br>
                    </td>
                </tr>
            <? } else { ?>
                <tr>
                    <td width="100%" colspan="6" align="left"><br><br>
                        <table width="100%" cellpadding="0" cellspacing="0" >
                            <td width="51%" height="45">
                                <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
                                    <input type="button" class="button" value="<<" onClick="window.open('order_view.php?page=1','_self')">
                                    <input type="button" class="button" value="<" onClick="window.open('order_view.php?page=<?= $prepage ?>','_self')">

                                    Page <input type="text" name="pageno" value="<?= $page ?>" size="2" maxlength="3" class="text"> of <?= $totalpage ?>
                                    <input type="submit" value="Go" class="button" name="btngo">
                                    <? if ($page == $totalpage) { ?>	
                                        <input type="button" class="button" value=">" >
                                    <? } else { ?>
                                        <input type="button" class="button" value=">" onClick="window.open('order_view.php?page=<?= $nextpage ?>','_self')">
                                    <? } ?>
                                    <input type="button" class="button" value=">>" onClick="window.open('order_view.php?page=<?= $totalpage ?>','_self')">

                                </form>

                            </td>

                        </table>
                    </td>
                </tr>
                <tr>
                    <td width="100%" colspan="4">
                        <table class="solidborder" width="100%" >
                            <tr class="table_header">
                                <td width="15%">Order #</td>
                                <td width="15%">Order Date</td>
                                <td width="15%">Buyer</td>
                                <td width="15%">Total Amount(<?= $module_currency_code ?>)</td> 
                                <td width="15%">Status</td>
                            </tr>
                            <?
                            $no = $from + 1;
                            while ($c = mysql_fetch_array($get_bill)) {
                                if ($no % 2 == 0) {
                                    $class1 = "table_item_even";
                                    $class2 = "table_item_odd";
                                } else {
                                    $class1 = "table_item_odd";
                                    $class2 = "table_item_even";
                                }

                                $get_member = mysql_query("select * from os_member where id=" . $c['uid']);

                                if (mysql_num_rows($get_member) == 0) {
                                    $name = "- user not found -";
                                } else {
                                    $name = "<a href='member_viewfull.php?id=" . mysql_result($get_member, 0, "id") . "'>" . mysql_result($get_member, 0, "username") . "</a>";
                                }
                                ?>	
                                <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover';this.style.cursor='pointer'" 
                                    onmouseout="this.className='<?= $class1 ?>'" onclick="window.open('order_viewfull.php?id=<?= $c['id'] ?>','_self')">
                                    <td><a href="order_viewfull.php?id=<?= $c['id'] ?>"><?= $c['order_request_number'] ?></a></td>
                                    <td><?= $c['create_date'] ?></td>
                                    <td><?= $c['receiver_name'] ?></td>
                                    <?
                                    if ($c['is_redeem'] == 1) {
                                        ?>

                                        <Td align="center" colspan="2">Gift Redemption</td>
                                        <?
                                    } else {
                                         $total_amount = $c['total_amount'] + $c['transport_fees'];
                                        ?>
                                        <td align="right"><font color="#FF0000"><?= number_format($total_amount, 2) ?></font></td>
                                        <td>
                                            <?= billstatus_eng($c['status']) ?>

                                        </td>
                                    <? } ?>


                                </tr>
                                <?
                                $no++;
                            }
                            ?>
                        </table>
                    </td>
<? } ?>

        </table>
    </td>
</table>

<? require("required/footer.php"); ?>

